﻿local UIScale = true					-- 自动缩放
local MoveChat = true       			-- 固定聊天框位置       
local AutoInvate = true     			-- 自动邀请符合密语者
local NoErrors = false       			-- 屏蔽红字提醒
local NoErrorsInCombat = false     		-- 战斗中屏蔽错误
local ChatFilter = false           		-- 聊天信息过滤
local MoveUIErrors = false        		-- Move UI errors on top(if you opted errors)
local IgnoreDuel = false          		-- 自动拒绝决斗
local AutoRoll = true					-- 自动贪婪绿色物品
local AutoLoot = true					-- 启动拾取切换
local AutoRepair = false				-- 自动修理
local SellGreyCrap = false				-- 自动贩卖灰色物品
local AcceptInvites = true				-- 自动接受邀请（好友或者工会内的人）
local BuyStack = true					-- 通过ALT+点击购买一堆叠物品
local AddItemToTrade = true				-- 通过ALT+点击物品与目标交易
local MoveInterfaceFrame = false		-- Move interface frame
local TalentSpam = true					-- 天赋切换报告
local QuestAutomation = false			-- 自动接任务
local QuestIcons = true					-- 高亮已完成的任务
local AutoRez = false					-- 战场自动释放
local StyleBGMap = true					-- 美化战场小地图
local LockQuest = true					-- 任务监视/载具框体

---------------------------------------------------- Changing some variables

local csf = CreateFrame("Frame")
csf:SetScript("OnEvent", function()
	SetCVar("showClock", 0)
	SetCVar("screenshotQuality", 8)
	SetCVar("cameraDistanceMax", 50)
	SetCVar("cameraDistanceMaxFactor", 2)
	SetCVar("screenshotFormat", "JPG")
	SetCVar("autoSelfCast", 1)
	SetCVar("lockActionBars", 0)
	SetCVar("alwaysShowActionBars", 1)
	SetCVar("lootUnderMouse", 1)
	SetCVar("secureAbilityToggle", 1)
	SetCVar("chatLocked", 0)
	SetCVar("CombatDamage", 1)
	SetCVar("CombatHealing", 1)
	SetCVar("miniWorldMap", 1)
	SetMultisampleFormat(1)
	-- Show class colors
	ToggleChatColorNamesByClassGroup(true, "SAY")
	ToggleChatColorNamesByClassGroup(true, "EMOTE")
	ToggleChatColorNamesByClassGroup(true, "YELL")
	ToggleChatColorNamesByClassGroup(true, "GUILD")
	ToggleChatColorNamesByClassGroup(true, "GUILD_OFFICER")
	ToggleChatColorNamesByClassGroup(true, "GUILD_ACHIEVEMENT")
	ToggleChatColorNamesByClassGroup(true, "ACHIEVEMENT")
	ToggleChatColorNamesByClassGroup(true, "WHISPER")
	ToggleChatColorNamesByClassGroup(true, "PARTY")
	ToggleChatColorNamesByClassGroup(true, "RAID")
	ToggleChatColorNamesByClassGroup(true, "RAID_LEADER")
	ToggleChatColorNamesByClassGroup(true, "RAID_WARNING")
	ToggleChatColorNamesByClassGroup(true, "BATTLEGROUND")
	ToggleChatColorNamesByClassGroup(true, "BATTLEGROUND_LEADER")
	ToggleChatColorNamesByClassGroup(true, "CHANNEL1")
	ToggleChatColorNamesByClassGroup(true, "CHANNEL2")
	ToggleChatColorNamesByClassGroup(true, "CHANNEL3")
	ToggleChatColorNamesByClassGroup(true, "CHANNEL4")
end)
csf:RegisterEvent("PLAYER_LOGIN")

---------------------------------------------------- Creating info text
local frame = CreateFrame("Frame", nil, UIParent)
frame:SetScript("OnUpdate", FadingFrame_OnUpdate)
frame.fadeInTime = 0.5
frame.fadeOutTime = 2
frame.holdTime = 3
frame:Hide()

local text = frame:CreateFontString("aInfoText", "OVERLAY")
text:SetFont(STANDARD_TEXT_FONT, 32, "THICKOUTLINE")
text:SetPoint("CENTER", UIParent, "CENTER")
text:SetTextColor(0.41, 0.8, 0.94)

aInfoText_ShowText = function(s)
    text:SetText(s)
    FadingFrame_Show(frame)
end

---------------------------------------------------- UI Scale
if(UIScale==true) then
	local Scales = {
		["576"] = 0.64,
		["600"] = 0.64,
		["720"] = 0.85,
		["768"] = 0.8,
		["800"] = 0.79,
		["864"] = 0.88888888888888,
		["900"] = 0.81999999284744,
		["960"] = 0.8,
		["1024"] = 0.75,
		["1050"] = 0.73142857142857,
		["1080"] = 0.71111111111111,
		["1200"] = 0.64,
	}

    local scalefix = CreateFrame("Frame")
    scalefix:RegisterEvent("PLAYER_LOGIN")
    scalefix:SetScript("OnEvent", function()
        local _, height = string.match((({GetScreenResolutions()})[GetCurrentResolution()] or ""), "(%d+).-(%d+)")
        if(height and Scales[height]) then
            SetCVar("useUiScale", 1)
            SetCVar("uiScale", Scales[height])
        else
            SetCVar("useUiScale", 0)
            if(tonumber(height)<768) then
                print("|cff00ffff"..L_SCALE)
            end
        end
    end)
end


---------------------------------------------------- Move Chat
if(MoveChat==true) then
local framesetup = CreateFrame("Frame", nil, UIParent)
framesetup:RegisterEvent("PLAYER_ENTERING_WORLD")
framesetup:SetScript("OnEvent", function ()
	if event == "PLAYER_ENTERING_WORLD" then
		DEFAULT_CHATFRAME_ALPHA = 0
		ChatFrame1:ClearAllPoints()
		ChatFrame1:SetWidth(398)
		ChatFrame1:SetHeight(125)
		ChatFrame1:SetPoint('BOTTOMLEFT',UIParent,'BOTTOMLEFT',15,33)
		ChatFrame1:SetFrameLevel(5)
		ChatFrame1:SetUserPlaced(true)
		ChatFrame3:ClearAllPoints()
		ChatFrame3:SetPoint("BOTTOMRIGHT", UIParent, -15, 33)
		ChatFrame3:SetWidth(398)
		ChatFrame3:SetHeight(125)
		ChatFrame3:SetFrameLevel(5)
		ChatFrame3:SetJustifyH("RIGHT")
		ChatFrame3:SetUserPlaced(true);
		end	
end)
end

---------------------------------------------------- Questlog Position
if LockQuest == true then
	hooksecurefunc(WatchFrame,"SetPoint",function(_,_,parent) -- quest watch frame
		if (parent == "MinimapCluster") or (parent == _G["MinimapCluster"]) then
			-- this only happens if the user isn't using the advanced quest watcher
			WatchFrame:ClearAllPoints();
			WatchFrame:SetPoint("TOPRIGHT","UIParent","TOPRIGHT",-50,-200);
			WatchFrame:SetPoint("BOTTOMRIGHT","UIParent","BOTTOMRIGHT",-200,160);
		end
	end);
	
	hooksecurefunc(DurabilityFrame,"SetPoint",function(self,_,parent) -- durability frame
		if (parent == "MinimapCluster") or (parent == _G["MinimapCluster"]) then
			DurabilityFrame:ClearAllPoints();
			DurabilityFrame:SetPoint("BOTTOM",UIParent,"BOTTOM",0,160);
		end
	end);

	hooksecurefunc(VehicleSeatIndicator,"SetPoint",function(_,_,parent) -- vehicle seat indicator
		if (parent == "MinimapCluster") or (parent == _G["MinimapCluster"]) then
			VehicleSeatIndicator:ClearAllPoints();
			VehicleSeatIndicator:SetPoint("BOTTOMLEFT",UIParent,"BOTTOMLEFT", 280, 200);
		end
	end);
end

---------------------------------------------------- Auto Invate
if(AutoInvate==true) then
local Main = CreateFrame("Frame", "Main", UIParent)
Main:RegisterEvent("CHAT_MSG_WHISPER")
Main:SetScript("OnEvent", function(self, event, ...)

if ( event == "CHAT_MSG_WHISPER" ) then 
     if ( arg1 == "inv" or arg1 == "组我" or arg1 == "invite" or arg1 == "组" or arg1 == "1" or arg1 == "222") then
InviteUnit(arg2)
end
     end
end)
end


---------------------------------------------------- No Errors
if(NoErrors==true) then 
UIErrorsFrame:UnregisterEvent("UI_ERROR_MESSAGE") 
end


---------------------------------------------------- AutoLoot
if(AutoLoot==true) then
function SimpleAutoLoot_OnEvent()
	if(GetNumRaidMembers() > 0) then
		if GetCVar("autoLootDefault") == "1" then
			DEFAULT_CHAT_FRAME:AddMessage(L_DISLOOT, 0, 1, 1 )
			SetCVar("autoLootDefault", "0")
		end
	else
		if GetCVar("autoLootDefault") == "0" then
			DEFAULT_CHAT_FRAME:AddMessage(L_ENLOOT, 0, 1, 1 )
			SetCVar("autoLootDefault", "1")
		end
	end
end

local frame = CreateFrame("Frame", "SimpleAutoLootFrame")

frame:RegisterEvent("ADDON_LOADED")
frame:RegisterEvent("PLAYER_LOGIN")
frame:RegisterEvent("PARTY_MEMBERS_CHANGED")

frame:SetScript("OnEvent", SimpleAutoLoot_OnEvent)
end

---------------------------------------------------- Remove errors in combat
if(NoErrorsInCombat==true) then 
local neic = CreateFrame("Frame")
local OnEvent = function(self, event, ...) self[event](self, event, ...) end
neic:SetScript("OnEvent", OnEvent)

local function PLAYER_REGEN_DISABLED()
	UIErrorsFrame:Hide()
end

local function PLAYER_REGEN_ENABLED()
	UIErrorsFrame:Show()
end

neic:RegisterEvent("PLAYER_REGEN_DISABLED")
neic["PLAYER_REGEN_DISABLED"] = PLAYER_REGEN_DISABLED

neic:RegisterEvent("PLAYER_REGEN_ENABLED")
neic["PLAYER_REGEN_ENABLED"] = PLAYER_REGEN_ENABLED
end


---------------------------------------------------- Chat Filter
if(ChatFilter==true) then
ChatFrame_AddMessageEventFilter("CHAT_MSG_CHANNEL_JOIN", function(msg) return true end)
ChatFrame_AddMessageEventFilter("CHAT_MSG_CHANNEL_LEAVE", function(msg) return true end)
ChatFrame_AddMessageEventFilter("CHAT_MSG_CHANNEL_NOTICE", function(msg) return true end)
ChatFrame_AddMessageEventFilter("CHAT_MSG_AFK", function(msg) return true end)
ChatFrame_AddMessageEventFilter("CHAT_MSG_DND", function(msg) return true end)
DUEL_WINNER_KNOCKOUT, DUEL_WINNER_RETREAT = "", ""
DRUNK_MESSAGE_ITEM_OTHER1 = "", ""
DRUNK_MESSAGE_ITEM_OTHER2 = "", ""
DRUNK_MESSAGE_ITEM_OTHER3 = "", ""
DRUNK_MESSAGE_ITEM_OTHER4 = "", ""
DRUNK_MESSAGE_OTHER1 = "", ""
DRUNK_MESSAGE_OTHER2 = "", ""
DRUNK_MESSAGE_OTHER3 = "", ""
DRUNK_MESSAGE_OTHER4 = "", ""
DRUNK_MESSAGE_ITEM_SELF1 = "", ""
DRUNK_MESSAGE_ITEM_SELF2 = "", ""
DRUNK_MESSAGE_ITEM_SELF3 = "", ""
DRUNK_MESSAGE_ITEM_SELF4 = "", ""
DRUNK_MESSAGE_SELF1 = "", ""
DRUNK_MESSAGE_SELF2 = "", ""
DRUNK_MESSAGE_SELF3 = "", ""
DRUNK_MESSAGE_SELF4 = "", ""
CHAT_FLAG_AFK = "[AFK] "
CHAT_FLAG_DND = "[DND] "
end

---------------------------------------------------- Move UIErrors frame
if(MoveUIErrors==true) then
UIErrorsFrame:ClearAllPoints()
UIErrorsFrame:SetPoint("TOP", UIParent, "TOP", 0, -30)
UIErrorsFrame.SetPoint = dummy
end


---------------------------------------------------- Ignore Duel 
if(IgnoreDuel==true) then
local dd = CreateFrame("Frame")
    dd:RegisterEvent("DUEL_REQUESTED")
    dd:SetScript("OnEvent", function(self, event, name)
        HideUIPanel(StaticPopup1)
        CancelDuel()
		aInfoText_ShowText(L_DUEL..name) -- new info text
    end)
end


---------------------------------------------------- Auto resurection
if(AutoRez==true) then
	local ar = CreateFrame("Frame")
	local OnEvent = function(self, event, ...) self[event](self, event, ...) end
	ar:SetScript("OnEvent", OnEvent)
	local function PLAYER_DEAD()
	if MiniMapBattlefieldFrame.status and MiniMapBattlefieldFrame.status=="active" then
		RepopMe()
	end
	end
	ar:RegisterEvent("PLAYER_DEAD")
	ar["PLAYER_DEAD"] = PLAYER_DEAD
end

---------------------------------------------------- Auto Roll
if(AutoRoll==true) then
    local f = CreateFrame("Frame")
    f:RegisterEvent("START_LOOT_ROLL")
    f:SetScript("OnEvent", function(_, _, id)
        if(id and select(4, GetLootRollItemInfo(id))==2) then
            RollOnLoot(id, 2)
        end
    end)
end


---------------------------------------------------- Auto repair & sell crap
local arsc = CreateFrame("Frame")
	arsc:RegisterEvent("MERCHANT_SHOW")
	arsc:SetScript("OnEvent", function()
    if(AutoRepair==true and CanMerchantRepair()) then
        local cost = GetRepairAllCost()
        if(not cost or cost==0) then return end

        local CanGuildRepair = AutoRepairGuildBank==true and IsInGuild() and CanGuildBankRepair() and GetGuildBankWithdrawMoney()>cost and GetGuildBankMoney()>cost
        if(CanGuildRepair) then
            RepairAllItems(1)
            aInfoText_ShowText(format(L_COST.."%.1f"..L_GOLD, cost * 0.0001))
			print(format("|cff00ffff"..L_COST.."%.1f"..L_GOLD.."|r", cost * 0.0001))
        elseif(GetMoney()>cost) then
            RepairAllItems()
            aInfoText_ShowText(format(L_COST.."%.1f"..L_GOLD, cost * 0.0001))
			print(format("|cff00ffff"..L_COST.."%.1f"..L_GOLD.."|r", cost * 0.0001))
        end
    end

    if(SellGreyCrap==true) then
        local bag, slot 
        for bag = 0, 4 do
            for slot = 0, GetContainerNumSlots(bag) do
                local link = GetContainerItemLink(bag, slot)
                if link and (select(3, GetItemInfo(link))==0) then
                    UseContainerItem(bag, slot)
                end
            end
        end
    end
end)

---------------------------------------------------- Accept Invites 
if(AcceptInvites==true) then
	local ai = CreateFrame("Frame")
	local OnEvent = function(self, event, ...) self[event](self, event, ...) end
	ai:SetScript("OnEvent", OnEvent)

	local function PARTY_MEMBERS_CHANGED()
		StaticPopup_Hide("PARTY_INVITE")
		ai:UnregisterEvent("PARTY_MEMBERS_CHANGED")
	end

	local InGroup = false
	local function PARTY_INVITE_REQUEST()
		local leader = arg1
		InGroup = false
	
	-- Update Guild and Freindlist
		if GetNumFriends() > 0 then ShowFriends() end
		if IsInGuild() then GuildRoster() end
	
		for friendIndex = 1, GetNumFriends() do
			local friendName = GetFriendInfo(friendIndex)
			if friendName == leader then
				aInfoText_ShowText(L_INVITE..leader) -- new info text
				ChatFrame1:AddMessage(L_INVITE..leader, 0, 1, 1) -- old info text
				AcceptGroup()
				ai:RegisterEvent("PARTY_MEMBERS_CHANGED")
				ai["PARTY_MEMBERS_CHANGED"] = PARTY_MEMBERS_CHANGED
				InGroup = true
				break
			end
		end
	
		if not InGroup then
			for guildIndex = 1, GetNumGuildMembers(true) do
				local guildMemberName = GetGuildRosterInfo(guildIndex)
				if guildMemberName == leader then
					AcceptGroup()
					ai:RegisterEvent("PARTY_MEMBERS_CHANGED")
					ai["PARTY_MEMBERS_CHANGED"] = PARTY_MEMBERS_CHANGED
					InGroup = true
					break
				end
			end
		end
	
		if not InGroup then
			SendWho(leader)
		end
	end
	ai:RegisterEvent("PARTY_INVITE_REQUEST")
	ai["PARTY_INVITE_REQUEST"] = PARTY_INVITE_REQUEST
end

---------------------------------------------------- ALT+Click to buy a stack
if(BuyStack==true) then
local savedMerchantItemButton_OnModifiedClick = MerchantItemButton_OnModifiedClick;
function MerchantItemButton_OnModifiedClick(self, ...)
	if ( IsAltKeyDown() ) then
		local maxStack = select(8, GetItemInfo(GetMerchantItemLink(this:GetID())));
		local name, texture, price, quantity, numAvailable, isUsable, extendedCost = GetMerchantItemInfo(this:GetID());
		if ( maxStack and maxStack > 1 ) then
			BuyMerchantItem(this:GetID(), floor(maxStack / quantity));
		end;
	end;
	savedMerchantItemButton_OnModifiedClick(self, ...);
end;
end


---------------------------------------------------- Some slash commands
SlashCmdList["FRAME"] = function() print(GetMouseFocus():GetName()) end
SLASH_FRAME1 = "/gn"

SlashCmdList["GETPARENT"] = function() print(GetMouseFocus():GetParent():GetName()) end
SLASH_GETPARENT1 = "/gp"

SlashCmdList["RELOADUI"] = function() ReloadUI() end
SLASH_RELOADUI1 = "/rl"

SlashCmdList["RCSLASH"] = function() DoReadyCheck() end
SLASH_RCSLASH1 = "/rc"

SlashCmdList["TICKET"] = function() ToggleHelpFrame() end
SLASH_TICKET1 = "/ticket"
SLASH_TICKET2 = "/gm"

SlashCmdList["DISABLE_ADDON"] = function(s) DisableAddOn(s) end
SLASH_DISABLE_ADDON1 = "/dis"

SlashCmdList["ENABLE_ADDON"] = function(s) EnableAddOn(s) end
SLASH_ENABLE_ADDON1 = "/en"

---------------------------------------------------- Addon's Group
local raidaddons = {    -- Addons you use only in raids or groups
    "sThreatMeter2", 
	"Engravings",
	"Skada",
	"SkadaDamage",
	"SkadaHealing",
	"SkadaFailbot",
	"RatingBuster",
    "DBM-Core",
	"BigWigs",
	"CheckForConsumables",
	"AntiSlack",
	"BigBrother",
	"Omen",
	"Recount",
}

local pvpaddons = {     -- Addons you use only in arenas or BGs. Nothing here since i rarely do PvP =)
    "Gladius", 
	"Engravings",
	"ArenaHistorian",
	"SpellAlerter",
	"PreformAVEnabler",
	"DRTracker",
	"RatingBuster",
	"SSArena",
	"ArenaCountDown",
	"Capping",
	"BattleInfo",
}

local soloaddons = {     -- Addons you use only in arenas or BGs. Nothing here since i rarely do PvP =)
    "QuestHelper",
	"LightHeaded",
	"Cartographer",
	"QuestLibrary",
	"MapNotes",
	"Carbonite",
}

local tradeaddons = {     
    "BaudAuction",
}

SlashCmdList["CHANGEADDONS"] = function(s)
    if(s and s=="raid") then
        for i in pairs(pvpaddons) do
            DisableAddOn(pvpaddons[i])
        end
		for i in pairs(soloaddons) do
            DisableAddOn(soloaddons[i])
        end
		for i in pairs(tradeaddons) do
            DisableAddOn(tradeaddons[i])
        end		
        for i in pairs(raidaddons) do
            EnableAddOn(raidaddons[i])
        end
        ReloadUI()
    elseif(s and s=="pvp") then
        for i in pairs(raidaddons) do
            DisableAddOn(raidaddons[i])
        end
		for i in pairs(soloaddons) do
            DisableAddOn(soloaddons[i])
        end
		for i in pairs(tradeaddons) do
            DisableAddOn(tradeaddons[i])
        end	
        for i in pairs(pvpaddons) do
            EnableAddOn(pvpaddons[i])
        end
        ReloadUI()
    elseif(s and s=="solo") then
        for i in pairs(raidaddons) do
            DisableAddOn(raidaddons[i])
        end
        for i in pairs(pvpaddons) do
            DisableAddOn(pvpaddons[i])
        end
		for i in pairs(tradeaddons) do
            DisableAddOn(tradeaddons[i])
        end	
		for i in pairs(soloaddons) do
            EnableAddOn(soloaddons[i])
        end
        ReloadUI()
    elseif(s and s=="trade") then
        for i in pairs(raidaddons) do
            DisableAddOn(raidaddons[i])
        end
        for i in pairs(pvpaddons) do
            DisableAddOn(pvpaddons[i])
        end
		for i in pairs(tradeaddons) do
            DisableAddOn(tradeaddons[i])
        end	
		for i in pairs(soloaddons) do
            DisableAddOn(soloaddons[i])
        end
		for i in pairs(tradeaddons) do
            EnableAddOn(tradeaddons[i])
        end	
        ReloadUI()
    else
		print(L_RAID)
		print(L_SOLO)
		print(L_PVP)
		print(L_TRADE)
    end
end
SLASH_CHANGEADDONS1 = "/ad"

---------------------------------------------------- Alt Click To Add Item Trade
if(AddItemToTrade==true) then
if IS_WRATH_BUILD == nil then IS_WRATH_BUILD = (select(4, GetBuildInfo()) >= 30000) end

local targ, bag, slot

local orig1 = ContainerFrameItemButton_OnModifiedClick
ContainerFrameItemButton_OnModifiedClick = function(...)
	local self, button
	if IS_WRATH_BUILD then self, button = ... else button = ... end
  if button == "LeftButton" and IsAltKeyDown() and not CursorHasItem() then
    bag, slot = this:GetParent():GetID(), this:GetID()
		if TradeFrame:IsVisible() then
      for i=1,6 do
        if not GetTradePlayerItemLink(i) then
					PickupContainerItem(bag, slot)
          ClickTradeButton(i)
					bag, slot = nil, nil
					return
        end
      end
    elseif not CursorHasItem() and UnitExists("target") and UnitIsFriend("player", "target") and UnitIsPlayer("target") and CheckInteractDistance("target", 2) then
      targ = UnitName("target")
      InitiateTrade("target")
      return
    end
  end
  orig1(...)
end
local function posthook(...)
  if targ and not CursorHasItem() and UnitName("target") == targ then
    PickupContainerItem(bag, slot)
    ClickTradeButton(1)
  end
  targ, bag, slot = nil, nil, nil

	return ...
end
local orig2 = TradeFrame:GetScript("OnShow")
TradeFrame:SetScript("OnShow", function(...)
	if orig2 then return posthook(orig2(...))
	else posthook() end
end)
end

---------------------------------------------------- Move Interface Frame
if(MoveInterfaceFrame==true) then
local mif = CreateFrame("Frame")
local frames = {
  ["InterfaceOptionsFrame"] = false,
}

local lodFrames = {
  Blizzard_GMSurveyUI = { ["GMSurveyFrame"] = false },
}

local parentFrame = {}
local hooked = {}

function mif:PLAYER_LOGIN()
  self:HookFrames(frames)
end

function mif:ADDON_LOADED(name)
  local frameList = lodFrames[name]
  if frameList then
    self:HookFrames(frameList)
  end
end

local function MouseDownHandler(frame, button)
  frame = parentFrame[frame] or frame
  if frame and button == "LeftButton" then
    frame:StartMoving()
    frame:SetUserPlaced(false)
  end
end

local function MouseUpHandler(frame, button)
  frame = parentFrame[frame] or frame
  if frame and button == "LeftButton" then
    frame:StopMovingOrSizing()
  end
end

function mif:HookFrames(list)
  for name, child in pairs(list) do
    self:HookFrame(name, child)
  end
end

function mif:HookFrame(name, moveParent)
  local frame = _G[name]
  local parent
  if frame and not hooked[name] then
    if moveParent then
      if type(moveParent) == "string" then
        parent = _G[moveParent]
      else
        parent = frame:GetParent()
      end
      if not parent then
        print("Parent frame not found: " .. name)
        return
      end
      parentFrame[frame] = parent
    end
    if parent then
      parent:SetMovable(true)
      parent:SetClampedToScreen(false)
    end
    frame:EnableMouse(true)
    frame:SetMovable(true)
    frame:SetClampedToScreen(false)
    self:HookScript(frame, "OnMouseDown", MouseDownHandler)
    self:HookScript(frame, "OnMouseUp", MouseUpHandler)
    hooked[name] = true
  end
end

function mif:HookScript(frame, script, handler)
  if not frame.GetScript then return end
  local oldHandler = frame:GetScript(script)
  if oldHandler then
    frame:SetScript(script, function(...)
      handler(...)
      oldHandler(...)
    end)
  else
    frame:SetScript(script, handler)
  end
end

mif:SetScript("OnEvent", function(f, e, ...) f[e](f, ...) end)
mif:RegisterEvent("PLAYER_LOGIN")
mif:RegisterEvent("ADDON_LOADED")
end


---------------------------------------------------- Hide spam from talent respec
if(TalentSpam==true) then
local spamFilterMatch1 = string.gsub(ERR_LEARN_ABILITY_S:gsub('%.', '%.'), '%%s', '(.*)')
local spamFilterMatch2 = string.gsub(ERR_LEARN_SPELL_S:gsub('%.', '%.'), '%%s', '(.*)')
local spamFilterMatch3 = string.gsub(ERR_SPELL_UNLEARNED_S:gsub('%.', '%.'), '%%s', '(.*)')
local primarySpecSpellName = GetSpellInfo(63645)
local secondarySpecSpellName = GetSpellInfo(63644)

local groupNamesCaps = {
	"Primary",
	"Secondary"
}

specCache = {}
	
HideSpam = CreateFrame("Frame");
HideSpam:RegisterEvent("ACTIVE_TALENT_GROUP_CHANGED");
HideSpam:RegisterEvent("UNIT_SPELLCAST_START");
HideSpam:RegisterEvent("UNIT_SPELLCAST_INTERRUPTED");

HideSpam.filter = function(self, event, msg, ...)
	if strfind(msg, spamFilterMatch1) then
		return true
	elseif strfind(msg, spamFilterMatch2) then
		return true
	elseif strfind(msg, spamFilterMatch3) then
		return true
	end
	return false, msg, ...
end

HideSpam:SetScript("OnEvent", function( self, event, ...)

	local unit, spellName = ...
	
	if(event == "UNIT_SPELLCAST_START") then
		if unit == "player" and (spellName == primarySpecSpellName or spellName == secondarySpecSpellName) then
			ChatFrame_AddMessageEventFilter("CHAT_MSG_SYSTEM", self.filter)
		end
	
	elseif(event == "UNIT_SPELLCAST_INTERRUPTED") then
		if unit == "player" and (spellName == primarySpecSpellName or spellName == secondarySpecSpellName) then
			ChatFrame_RemoveMessageEventFilter("CHAT_MSG_SYSTEM", self.filter)
		end
	
	elseif(event == "ACTIVE_TALENT_GROUP_CHANGED") then
		for i = 1, GetNumTalentGroups() do
			specCache[i] = specCache[i] or {}
			local thisCache = specCache[i]
			TalentFrame_UpdateSpecInfoCache(thisCache, false, false, i)
			if thisCache.primaryTabIndex and thisCache.primaryTabIndex ~= 0 then
				thisCache.specName = thisCache[thisCache.primaryTabIndex].name
				thisCache.mainTabIcon = thisCache[thisCache.primaryTabIndex].icon
			elseif thisCache.secondaryTabIndex and thisCache.secondaryTabIndex ~= 0 then
				thisCache.specName = thisCache[thisCache.secondaryTabIndex].name
				thisCache.mainTabIcon = thisCache[thisCache.secondaryTabIndex].icon
			else
				thisCache.specName = "|cffff0000Talents undefined!|r"
				thisCache.mainTabIcon = "Interface\\Icons\\Ability_Seal"
			end
			thisCache.specGroupName = groupNamesCaps[i]
		end

		local activeGroupNum = GetActiveTalentGroup()
		if specCache[activeGroupNum].totalPointsSpent > 1 then
			local s = specCache[activeGroupNum];
			print(L_TALENT.."|cff6adb54".. s.specName .." ("..
			s[1].pointsSpent .."/"..
			s[2].pointsSpent .."/"..
			s[3].pointsSpent ..")|r"..L_TALENT_S)
		end
		
		ChatFrame_RemoveMessageEventFilter("CHAT_MSG_SYSTEM", self.filter)

	end

end);
end


---------------------------------------------------- Quest Automation
if(QuestAutomation==true) then
local qauto = CreateFrame('Frame')
qauto.completed_quests = {}
qauto.uncompleted_quests = {}

function qauto:canAutomate ()
	if IsShiftKeyDown() then
		return false
	else
		return true
	end
end

function qauto:strip_text (text)
	if not text then return end
	text = text:gsub('%[.*%]%s*','')
	text = text:gsub('|c%x%x%x%x%x%x%x%x(.+)|r','%1')
	text = text:gsub('(.+) %(.+%)', '%1')
	text = text:trim()
	return text
end

function qauto:QUEST_PROGRESS ()
	if not self:canAutomate() then return end
	if IsQuestCompletable() then
		CompleteQuest()
	end
end

function qauto:QUEST_LOG_UPDATE ()
	if not self:canAutomate() then return end
	local start_entry = GetQuestLogSelection()
	local num_entries = GetNumQuestLogEntries()
	local title
	local is_complete
	local no_objectives

	self.completed_quests = {}
	self.uncompleted_quests = {}

	if num_entries > 0 then
		for i = 1, num_entries do
			SelectQuestLogEntry(i)
			title, _, _, _, _, _, is_complete = GetQuestLogTitle(i)
			no_objectives = GetNumQuestLeaderBoards(i) == 0
			if title and (is_complete or no_objectives) then
				self.completed_quests[title] = true
			else
				self.uncompleted_quests[title] = true
			end
		end
	end

	SelectQuestLogEntry(start_entry)
end

function qauto:GOSSIP_SHOW ()
	if not self:canAutomate() then return end

	local button
	local text

	for i = 1, 32 do
		button = _G['GossipTitleButton' .. i]
		if button:IsVisible() then
			text = self:strip_text(button:GetText())
			if button.type == 'Available' then
				button:Click()
			elseif button.type == 'Active' then
				if self.completed_quests[text] then
					button:Click()
				end
			end
		end
	end
end

function qauto:QUEST_GREETING (...)
	if not self:canAutomate() then return end

	local button
	local text

	for i = 1, 32 do
		button = _G['QuestTitleButton' .. i]
		if button:IsVisible() then
			text = self:strip_text(button:GetText())
			if self.completed_quests[text] then
				button:Click()
			elseif not self.uncompleted_quests[text] then
				button:Click()
			end
		end
	end
end

function qauto:QUEST_DETAIL ()
	if not self:canAutomate() then return end
	AcceptQuest()
end

function qauto:QUEST_COMPLETE (event)
	if not self:canAutomate() then return end
	if GetNumQuestChoices() <= 1 then
		GetQuestReward(QuestFrameRewardPanel.itemChoice)
	end
end

function qauto.onevent (self, event, ...)
	if self[event] then
		self[event](self, ...)
	end
end

qauto:SetScript('OnEvent', qauto.onevent)
qauto:RegisterEvent('GOSSIP_SHOW')
qauto:RegisterEvent('QUEST_COMPLETE')
qauto:RegisterEvent('QUEST_DETAIL')
qauto:RegisterEvent('QUEST_FINISHED')
qauto:RegisterEvent('QUEST_GREETING')
qauto:RegisterEvent('QUEST_LOG_UPDATE')
qauto:RegisterEvent('QUEST_PROGRESS')

_G.idQuestAutomation = qauto
end


---------------------------------------------------- Quest Icons
if(QuestIcons==true) then
local _G = getfenv(0)

-- Tries to deal with incompatabilities that other mods cause
local function stripStupid(text)
	if( not text ) then
		return nil
	end
	
	-- Strip [<level crap>] <quest title>
	text = string.gsub(text, "%[(.+)%]", "")
	-- Strip color codes
	text = string.gsub(text, "|c%x%x%x%x%x%x%x%x(.+)|r", "%1")
	-- Strip (low level) at the end of a quest
	text = string.gsub(text, "(.+) %((.+)%)", "%1")
	
	text = string.trim(text)
	text = string.lower(text)
	return text
end

function checkQuestText(buttonText, texture)
	buttonText = stripStupid(buttonText)
	
	for i=1, GetNumQuestLogEntries() do
		local questName, _, _, _, _, _, isComplete = GetQuestLogTitle(i)
		
		if( buttonText == stripStupid(questName) ) then
			if( ( isComplete and isComplete > 0 ) or GetNumQuestLeaderBoards(i) == 0 ) then
				SetDesaturation(texture, nil)
				return
			end
			break
		end
	end
		
	SetDesaturation(texture, true)
end

local function updateGossipIcons()
	if( not GossipFrame:IsVisible() ) then
		return
	end
	
	for i=1, GossipFrame.buttonIndex do
		local button = _G["GossipTitleButton" .. i]
		if( button:IsVisible() ) then
			if( button.type == "Active" ) then
				checkQuestText(button:GetText(), _G[button:GetName() .. "GossipIcon"])
			else
				SetDesaturation(_G[button:GetName() .. "GossipIcon"], nil)
			end
		end
	end
end

local function updateQuestIcons()
	if( not QuestFrameGreetingPanel:IsVisible() ) then
		return
	end
	
	for i=1, (GetNumActiveQuests() + GetNumAvailableQuests()) do
		local button = _G["QuestTitleButton" .. i]
		if( button:IsVisible() ) then
			if( button.isActive == 1 ) then
				checkQuestText(button:GetText(), (button:GetRegions()))
			else
				SetDesaturation((button:GetRegions()), nil)
			end
		end
	end
end

local frame = CreateFrame("Frame")
frame:RegisterEvent("QUEST_GREETING")
frame:RegisterEvent("GOSSIP_SHOW")
frame:RegisterEvent("QUEST_LOG_UPDATE")
frame:SetScript("OnEvent", function(self, event)
	updateQuestIcons()
	updateGossipIcons()
end)
end

---------------------------------------------------- Addons settings
--[[ General settings config ]]
local eSetUI = function()	
	FCF_ResetChatWindows()
	FCF_DockFrame(ChatFrame2)

	FCF_OpenNewWindow("EP")
	FCF_UnDockFrame(ChatFrame3)
	FCF_SetLocked(ChatFrame3, 1);
	--ChatFrame3:Show();
	
	-- Setup chat
	ChatFrame_RemoveAllMessageGroups(ChatFrame1)
	ChatFrame_RemoveChannel(ChatFrame1, "交易")
	ChatFrame_RemoveChannel(ChatFrame1, "綜合")
	ChatFrame_RemoveChannel(ChatFrame1, "综合")
	ChatFrame_RemoveChannel(ChatFrame1, "尋求組隊")
	ChatFrame_AddMessageGroup(ChatFrame1, "SAY")
	ChatFrame_AddMessageGroup(ChatFrame1, "EMOTE")
	ChatFrame_AddMessageGroup(ChatFrame1, "YELL")
	ChatFrame_AddMessageGroup(ChatFrame1, "GUILD")
	ChatFrame_AddMessageGroup(ChatFrame1, "GUILD_OFFICER")
	ChatFrame_AddMessageGroup(ChatFrame1, "GUILD_ACHIEVEMENT")
	ChatFrame_AddMessageGroup(ChatFrame1, "WHISPER")
	ChatFrame_AddMessageGroup(ChatFrame1, "MONSTER_SAY")
	ChatFrame_AddMessageGroup(ChatFrame1, "MONSTER_EMOTE")
	ChatFrame_AddMessageGroup(ChatFrame1, "MONSTER_YELL")
	ChatFrame_AddMessageGroup(ChatFrame1, "MONSTER_WHISPER")
	ChatFrame_AddMessageGroup(ChatFrame1, "MONSTER_BOSS_EMOTE")
	ChatFrame_AddMessageGroup(ChatFrame1, "MONSTER_BOSS_WHISPER")
	ChatFrame_AddMessageGroup(ChatFrame1, "PARTY")
	ChatFrame_AddMessageGroup(ChatFrame1, "RAID")
	ChatFrame_AddMessageGroup(ChatFrame1, "RAID_LEADER")
	ChatFrame_AddMessageGroup(ChatFrame1, "RAID_WARNING")
	ChatFrame_AddMessageGroup(ChatFrame1, "BATTLEGROUND")
	ChatFrame_AddMessageGroup(ChatFrame1, "BATTLEGROUND_LEADER")
	ChatFrame_AddMessageGroup(ChatFrame1, "BG_HORDE")
	ChatFrame_AddMessageGroup(ChatFrame1, "BG_ALLIANCE")
	ChatFrame_AddMessageGroup(ChatFrame1, "BG_NEUTRAL")
	ChatFrame_AddMessageGroup(ChatFrame1, "AFK")
	ChatFrame_AddMessageGroup(ChatFrame1, "DND")
	ChatFrame_AddMessageGroup(ChatFrame1, "IGNORED")
	ChatFrame_AddMessageGroup(ChatFrame1, "SYSTEM")
	

	ChatFrame_RemoveAllMessageGroups(ChatFrame3)
	ChatFrame_AddChannel(ChatFrame3, "交易")
	ChatFrame_AddChannel(ChatFrame3, "綜合")
	ChatFrame_AddChannel(ChatFrame3, "综合")
	ChatFrame_AddChannel(ChatFrame3, "尋求組隊")
	ChatFrame_AddMessageGroup(ChatFrame3, "General")
	ChatFrame_AddMessageGroup(ChatFrame3, "COMBAT_XP_GAIN")
	ChatFrame_AddMessageGroup(ChatFrame3, "COMBAT_HONOR_GAIN")
	ChatFrame_AddMessageGroup(ChatFrame3, "COMBAT_FACTION_CHANGE")
	ChatFrame_AddMessageGroup(ChatFrame3, "LOOT")
	ChatFrame_AddMessageGroup(ChatFrame3, "MONEY")
	ChatFrame_AddMessageGroup(ChatFrame3, "ERRORS")
	ChatFrame_AddMessageGroup(ChatFrame3, "ACHIEVEMENT")
	
	FCF_SetWindowColor(ChatFrame3, 0, 0, 0)
    FCF_SetWindowAlpha(ChatFrame3, 0)

		
	-- Setup General, Trade, and LFG colors
	ChangeChatColor("CHANNEL2", 0.4, 0.4, 0.4)
	ChangeChatColor("CHANNEL4", 0/255, 153/255, 204/255)
end


--[[ DBM settings ]]
local _, class = UnitClass("player")
local t = RAID_CLASS_COLORS[class]
local r, g, b = t.r, t.g, t.b

local UploadBoss = function()
    if(DBM_SavedOptions) then table.wipe(DBM_SavedOptions) end

    DBM_SavedOptions = {
        ["ShowMinimapButton"] = false,
        ["ShowWarningsInChat"] = true,
        ["RangeFramePoint"] = "BOTTOM",
        ["RaidWarningSound"] = "Sound\\Doodad\\BellTollNightElf.wav",
        ["SpecialWarningSound"] = "Sound\\Spells\\PVPFlagTaken.wav",
        ["AutoRespond"] = false,
        ["StatusEnabled"] = false,
        ["RaidWarningPosition"] = {["Y"] = -150, ["X"] = 0, ["Point"] = "TOP"},
        ["Enabled"] = true,
        ["RangeFrameX"] = 225,
        ["RangeFrameY"] = 185,
        ["WarningIconLeft"] = true,
        ["WarningColors"] = {{["b"] = b, ["g"] = g, ["r"] = r,},
                             {["b"] = b, ["g"] = g, ["r"] = r,},
                             {["b"] = b, ["g"] = g, ["r"] = r,},
                             {["b"] = b, ["g"] = g, ["r"] = r,},},
        ["WarningIconRight"] = true,
        ["ShowFakedRaidWarnings"] = false,
        ["ShowMinimapButton"] = true,
        ["HPFramePoint"] = "TOPLEFT",
        ["HPFrameX"] = 240,
        ["HPFrameY"] = -240,
        ["SpamBlockRaidWarning"] = true,
        ["SpamBlockBossWhispers"] = false,
        ["HideBossEmoteFrame"] = false,
    }

    if(DBT_SavedOptions) then table.wipe(DBT_SavedOptions) end

    DBT_SavedOptions = {
        ["DBM"] = {
            ["StartColorR"] = r,
            ["StartColorG"] = g,
            ["StartColorB"] = b,
            ["EndColorR"] = r,
            ["EndColorG"] = g,
            ["EndColorB"] = b,
            ["Scale"] = 1,
            ["Width"] = 250,
            ["TimerX"] = -143,
            ["TimerY"] = -250,
            ["BarXOffset"] = 0,
            ["BarYOffset"] = 2,
            ["IconLeft"] = false,
            ["IconRight"] = false,
            ["ExpandUpwards"] = false,
            ["Texture"] = "Interface\\AddOns\\eMedia\\blank",
            ["HugeBarsEnabled"] = false,
            ["HugeBarXOffset"] = 0,
            ["HugeBarYOffset"] = 0,
            ["HugeWidth"] = 200,
            ["HugeTimerY"] = -190,
            ["HugeTimerPoint"] = "TOPLEFT",
            ["HugeTimerX"] = 150,
            ["HugeScale"] = 1.05,
            ["TimerPoint"] = "TOPRIGHT",
        },
    }
    DBM_SavedOptions["ep_settings"] = true
    DBM_SavedOptions["ShowMinimapButton"] = false
end

--[[ Recount Settings ]]
local recount = function()
	if RecountDB or RecountPerCharDB then
		table.wipe(RecountDB)
		table.wipe(RecountPerCharDB)
	end
	RecountDB = {
	["ep_setiings"] = true,
	["profileKeys"] = {
		[""] = "Default",
	},
	["profiles"] = {
		["Default"] = {
			["GraphWindowY"] = 0,
			["MainWindow"] = {
				["ShowScrollbar"] = false,
				["Position"] = {
					["y"] = -10.40647875656032,
					["x"] = -20,
					["w"] = 300,
					["h"] = 200,
				},
				["BarText"] = {
					["NumFormat"] = 3,
				},
				["RowHeight"] = 16,
				["RowSpacing"] = 1,
			},
			["Colors"] = {
				["Window"] = {
					["Background"] = {
						["a"] = 0,
						["r"] = 0.0392156862745098,
						["g"] = 0.06666666666666667,
					},
					["Title"] = {
						["a"] = 0,
						["r"] = 0.8313725490196078,
						["g"] = 0.7176470588235294,
						["b"] = 1,
					},
					["Title Text"] = {
						["r"] = 1,
						["g"] = 1,
						["b"] = 1,
					},
				},
				["Bar"] = {
					["Bar Text"] = {
						["a"] = 1,
						["b"] = 0.592156862745098,
						["g"] = 0.592156862745098,
						["r"] = 0.592156862745098,
					},
					["Total Bar"] = {
						["a"] = 1,
						["r"] = 0.2,
						["g"] = 0.2,
						["b"] = 0.2,
					},
				},
			},
			["DetailWindowY"] = 104.0000005623091,
			["DetailWindowX"] = -20,
			["BarTextColorSwap"] = true,
			["GraphWindowX"] = 0,
			--["Locked"] = true,
			["BarTexture"] = "Flat",
			["CurDataSet"] = "CurrentFightData",
			["ClampToScreen"] = true,
			["GraphWindowX"] = 0,
			["MainWindowWidth"] = 300,
			["MainWindowHeight"] = 200,
		},
	},
}
	--RecountPerCharDB = { },
	RecountDB["ep_setiings"] = true
	--RecountPerCharDB["ep_setiings"] = true
end

--[[ MSBT Settings ]]
local msbt = function()
	if MSBTProfiles_SavedVars or MSBT_SavedMedia or MSBTProfiles_SavedVarsPerChar then
		table.wipe(MSBTProfiles_SavedVars)
		table.wipe(MSBT_SavedMedia)
		table.wipe(MSBTProfiles_SavedVarsPerChar)
	end
		MSBTProfiles_SavedVarsPerChar = {
		["currentProfileName"] = "Default",
		}
		MSBTProfiles_SavedVars = {
		["ep_setiings"] = true,
	["profileKeys"] = {
		[""] = "Default",
	},
	["profiles"] = {
		["Default"] = {
			["normalOutlineIndex"] = 2,
			["animationSpeed"] = 120,
			["triggers"] = {
				["MSBT_TRIGGER_LOW_MANA"] = {
					["disabled"] = true,
				},
			},
			["critOutlineIndex"] = 2,
			["creationVersion"] = "5.4.66",
			["critFontSize"] = 20,
			["powerThreshold"] = 40,
			["events"] = {
				["NOTIFICATION_COMBAT_ENTER"] = {
					["scrollArea"] = "Custom2",
				},
				["NOTIFICATION_PC_KILLING_BLOW"] = {
					["scrollArea"] = "Custom2",
				},
				["NOTIFICATION_MONEY"] = {
					["disabled"] = true,
				},
				["NOTIFICATION_ITEM_BUFF_FADE"] = {
					["disabled"] = true,
				},
				["NOTIFICATION_REP_LOSS"] = {
					["scrollArea"] = "Custom1",
				},
				["NOTIFICATION_BUFF"] = {
					["scrollArea"] = "Custom2",
				},
				["NOTIFICATION_LOOT"] = {
					["disabled"] = true,
				},
				["INCOMING_HEAL_CRIT"] = {
					["scrollArea"] = "Custom1",
				},
				["NOTIFICATION_POWER_LOSS"] = {
					["scrollArea"] = "Custom1",
				},
				["NOTIFICATION_REP_GAIN"] = {
					["scrollArea"] = "Custom1",
				},
				["NOTIFICATION_HONOR_GAIN"] = {
					["scrollArea"] = "Custom1",
				},
				["INCOMING_HEAL"] = {
					["scrollArea"] = "Custom1",
				},
				["NOTIFICATION_COMBAT_LEAVE"] = {
					["scrollArea"] = "Custom2",
				},
				["NOTIFICATION_POWER_GAIN"] = {
					["scrollArea"] = "Custom1",
				},
				["NOTIFICATION_SKILL_GAIN"] = {
					["scrollArea"] = "Custom1",
				},
				["NOTIFICATION_ENEMY_BUFF"] = {
					["scrollArea"] = "Custom2",
				},
				["NOTIFICATION_COOLDOWN"] = {
					["fontSize"] = false,
				},
				["NOTIFICATION_EXTRA_ATTACK"] = {
					["scrollArea"] = "Custom2",
				},
				["INCOMING_HOT_CRIT"] = {
					["scrollArea"] = "Custom1",
				},
				["INCOMING_HOT"] = {
					["scrollArea"] = "Custom1",
				},
				["NOTIFICATION_CP_GAIN"] = {
					["disabled"] = true,
				},
				["NOTIFICATION_BUFF_STACK"] = {
					["scrollArea"] = "Custom2",
				},
				["NOTIFICATION_CP_FULL"] = {
					["disabled"] = true,
				},
				["NOTIFICATION_BUFF_FADE"] = {
					["disabled"] = true,
				},
				["NOTIFICATION_ITEM_BUFF"] = {
					["scrollArea"] = "Custom2",
				},
			},
			["normalFontSize"] = 15,
			["scrollAreas"] = {
				["Notification"] = {
					["scrollHeight"] = 140,
					["offsetX"] = -150,
					["direction"] = "Up",
					["offsetY"] = 150,
					["scrollWidth"] = 300,
				},
				["Custom2"] = {
					["stickyTextAlignIndex"] = 1,
					["animationStyle"] = "Angled",
					["behavior"] = "AngleDown",
					["stickyDirection"] = "Down",
					["scrollHeight"] = 100,
					["name"] = "Action",
					["direction"] = "Right",
					["offsetY"] = -110,
					["textAlignIndex"] = 1,
					["offsetX"] = 100,
				},
				["Outgoing"] = {
					["stickyDirection"] = "Up",
					["direction"] = "Right",
					["scrollHeight"] = 100,
					["stickyBehavior"] = "Normal",
					["offsetY"] = 10,
					["animationStyle"] = "Angled",
					["behavior"] = "AngleUp",
				},
				["Static"] = {
					["offsetY"] = -200,
				},
				["Custom1"] = {
					["direction"] = "Left",
					["behavior"] = "AngleDown",
					["animationStyle"] = "Angled",
					["scrollHeight"] = 100,
					["offsetX"] = -140,
					["stickyTextAlignIndex"] = 3,
					["offsetY"] = -110,
					["textAlignIndex"] = 3,
					["name"] = "Heal",
				},
				["Incoming"] = {
					["direction"] = "Left",
					["stickyBehavior"] = "MSBT_NORMAL",
					["behavior"] = "AngleUp",
					["stickyDirection"] = "Up",
					["scrollHeight"] = 100,
					["offsetY"] = 10,
					["animationStyle"] = "Angled",
					["stickyAnimationStyle"] = "Static",
				},
			},
			["hideFullOverheals"] = true,
			["healThreshold"] = 500,
			["damageThreshold"] = 100,
		},
	},
}
MSBT_SavedMedia = {
	["sounds"] = {
	},
	["ep_setiings"] = true,
	["fonts"] = {
	},
}
	MSBTProfiles_SavedVars["ep_setiings"] = true
	MSBT_SavedMedia["ep_setiings"] = true
	MSBTProfiles_SavedVarsPerChar["ep_setiings"] = true
end

--[[ Slash commands handling ]]
local pr = function(msg)
    print("|cff00ffffeP's UI:|r", tostring(msg))
end

SLASH_eset1 = "/eset"
SlashCmdList["eset"] = function(msg)
    if(msg=="msbt") then
        msbt()
        ReloadUI()
    elseif(msg=="ui") then
        eSetUI()
        ReloadUI()
	elseif(msg=="recount") then
        recount()
        ReloadUI()
    elseif(msg=="boss") then
        UploadBoss()
        ReloadUI()	
    elseif(msg=="all") then
		eSetUI()
		msbt()
		recount()
		UploadBoss()
        ReloadUI()
    else
		pr(L_UI)
		pr(L_RECOUNT)
		pr(L_MSBT)
		pr(L_DBM)
        pr(L_ESET)
    end
end

---------------------------------------------------- Battlefield minimap styling
if(StyleBGMap==true) then	
local bm = CreateFrame("frame")
bm:RegisterEvent("ADDON_LOADED")
bm:SetScript("OnEvent", function(self, event, addon)
	if not BattlefieldMinimap_Update then return end
	self:SetParent(BattlefieldMinimap)
	self:SetScript("OnShow", function()
		BattlefieldMinimapCorner:Hide()
		BattlefieldMinimapBackground:Hide()
		BattlefieldMinimapCloseButton:Hide()
	end)
	local background = CreateFrame("Frame", "BACKGROUND", BattlefieldMinimap)
	background:SetBackdrop{
		bgFile = "Interface\\ChatFrame\\ChatFrameBackground",
		tile = true, tileSize = 16,
		insets = {left = 4, right = 4, top = 4, bottom = 4},
	}
	background:SetBackdropColor(r,g,b, 0)
	background:SetFrameLevel(0)
	background:SetPoint("TOPLEFT", -5, 5)
	background:SetPoint("BOTTOMRIGHT", -1, -1)

	local background2 = CreateFrame("Frame", "BACKGROUND", BattlefieldMinimap)
	background2:SetBackdrop{
		bgFile = "Interface\\ChatFrame\\ChatFrameBackground",
		tile = true, tileSize = 16,
		insets = {left = 4, right = 4, top = 4, bottom = 4},
	}
	background2:SetBackdropColor(0,0,0, 0)
	background2:SetFrameLevel(0)
	background2:SetPoint("TOPLEFT", -6, 6)
	background2:SetPoint("BOTTOMRIGHT", 0, -2)
	
	self:UnregisterEvent("ADDON_LOADED")
	self:SetScript("OnEvent", nil)
end)
end